<?php
// +----------------------------------------------------------------------
// | 零云 [ 简单 高效 卓越 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.lingyun.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com>
// +----------------------------------------------------------------------
namespace Home\Controller;

/**
 * 前台默认控制器
 * @author jry <598821125@qq.com>
 */
class IndexController extends HomeController
{
    /**
     * 默认方法
     * @author jry <598821125@qq.com>
     */
    public function index()
    {
		//首页品牌
		$model = M('admin_brand');
		
		$brand = $model->order('img_id desc')->select();
		
		// $this->assign('brand',$brand);	

		$brandimg = M('admin_upload');
		
		foreach($brand as $k=>$r){
            
			$brand_logo = $brandimg->where("id='$r[img_id]'")->order('id desc')->find();
			
			$brand[$k]['path'] = $brand_logo['path'];
			
		}
		//首页轮播
		$img = M('admin_img');
		
		$img1 = $img->order('img_id desc')->where('status=1')->select();
		
		$brandimg1 = M('admin_upload');
		
		foreach($img1 as $k=>$r){
            
			$brand_logo = $brandimg1->where("id='$r[img_id]'")->order('id desc')->find();
			
			$img1[$k]['path'] = $brand_logo['path'];
			
		}
		
		//首页导航
		$logo = M('admin_logo');
		
		$logo = $logo->order('id asc')->where('status=1')->select();
		
		$brandimg1 = M('admin_upload');
		
		foreach($logo as $k=>$r){
            
			$brand_logo = $brandimg1->where("id='$r[img_id]'")->order('id desc')->find();
			
			$logo[$k]['path'] = $brand_logo['path'];
			
		}
		//首页导航
		
		$toutiao = M('admin_toutiao');
		
		$toutiao = $toutiao->order('id desc')->where('status=1')->select();
	
		$this->assign('toutiao',$toutiao);
		$this->assign('logo',$logo);
		$this->assign('img',$img1);
		$this->assign('arr',$brand);	
        $this->display();
    }

	public function price(){
		
		$goods = M('admin_goods');
		
		$brand_id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
		
		//判断如果id为零 默认首页第一个 
		
		if($brand_id == 0){
			
			$model = M('admin_brand');
			
			$brand = $model->order('id desc')->field('id')->find();
			
		
			if($brand){
				
				$brand_id= $brand['id'];
				
			}else{
				$this->error('数据错误！');
				exit;
			}
			
		}
		
		//左上角品牌名称
			
		$model = M('admin_brand');
		
		$brand_id = $model->where('id='.$brand_id)->select();

		$this->assign('brand_id',$brand_id);
			

		//商品名称——左侧栏
		$goods_name = $goods->field('id,goods_name,brand_id')->where('brand_id='.$brand_id[0]['id'])->group('goods_name')->order('id asc')->select();

		if(!empty($goods_name)){
			foreach($goods_name as $k=>$v){
				$where = array();
				$where['brand_id'] = $brand_id[0]['id'];
				$where['goods_name'] = $v['goods_name'];
				$good_list= $goods->where($where)->select();
				$goods_name[$k]['goods_list'] = $good_list;
				
			}
		}

		$this->assign('goods_name',$goods_name);
		
		//品牌弹出框
		$model = M('admin_brand');
		
		$brand = $model->order('img_id desc')->select();		
		
		$this->assign('brand',$brand);

		$this->display();
	}
	

}
